import platform = require('../../../common/baseCommon');
import appClient = require('../../appClient');
import platformControls = require('../../controls');
import mainForm = require('../navbarMainForm');

/**
 * 模块名称
 */
const moduleName = "platform.client";

/**
 * 网页应用主视图
 */
@platform.addon("网页应用通用主视图", "网页应用通用主视图,用于PC端通用网页布局的主视图", moduleName)
@appClient.template("platform/client/mainForm/noneborder/noneborderMainForm.html",
    "platform/client/mainForm/noneborder/noneborderMainForm.css")
export class noneBorderMainForm extends mainForm.navbarMainForm {

    /**
     * 网页标题
     */
    title?: string;

    /**
     * 漂浮工具条
     */
    $floatTools?: JQuery = undefined;

    /**
     * 工具条
     */
    $tools?: JQuery = undefined;

    /**
     * 绑定事件
     */
    onAfterBind?() {
        // 渲染导航页面
        if (this.navPages) {
            for (let nav of this.navPages) {
                nav.onChangeView = (page: platformControls.tabPage) => {
                    this.changePage(page);
                };
                nav.appendTo(this.$navBar);
                nav.appendTo(this.$sidebar);
            }
        }
        let currentPage = mainForm.getCurrentPageByUrl(this.navPages);
        // 加载首页
        if (currentPage) {
            this.changePage(currentPage);
        } else if (this.navPages && this.navPages[0]) {
            this.changePage(this.navPages[0]);
        }
    }

    /**
     * 打开视图
     * @param view 视图
     */
    protected openView?(view: appClient.baseView): void {
        this.currentView = view;

        this.$title.html(view.caption);

        this.$content.children().hide();
        if (view.element) {
            $(view.element).show();
        } else {
            view.appendTo(this.$content[0]);
        }
        if (view.onShowed)
            view.onShowed();
    }

}
